package com.stone.serviceimpl;

import java.util.List;

import com.stone.daoimpl.AdminDao;
import com.stone.model.Admin;
import com.stone.service.IAdminService;
import com.stone.utils.Page;

public class AdminService implements IAdminService {
	
	private AdminDao adminDao;
	

	public AdminDao getAdminDao() {
		return adminDao;
	}


	public void setAdminDao(AdminDao adminDao) {
		this.adminDao = adminDao;
	}


	public boolean check(String userName, String password) {
		List<Admin> list = adminDao.findByProperty("username", userName);
		if(list.size() == 0){
			return false;
		}else{
			Admin admin = new Admin();
			admin = list.get(0);
			if(admin.getPassword().equals(password)){
				return true;
			}
		}
		return false;
	}


	public Admin findAdminByName(String userName) {
		List<Admin> list = adminDao.findByProperty("username", userName);
		if(list.size() == 0){
			return null;
		}else{
			return list.get(0);
		}
	}


	public void updateAdmin(Admin admin) {
		adminDao.update(admin);
	}


	public List<Admin> findAllAdministrators() {

		return adminDao.findAllAdministrators();
	}


	public Admin findAdminById(Long adminId) {
		
		return adminDao.findById(adminId);
	}


	public void deleteAdministrator(Admin admin) {
		
		adminDao.delete(admin);		
	}


	public void addAdministrator(Admin admin) {
		adminDao.save(admin);
		
	}
	

}
